#!/usr/bin/python3
# -*- coding: utf-8 -*-

# @Time    : 2018-11-07 00:42
# @Author  : chester7cheng
# @Email   : 346835646@qq.com
# @File    : sharding.py
# @Software: PyCharm

l = ['m', 's', 't', 'e', 'j']

print(l[0:3])
print(l[-2])

l = list(range(100))

print(l)
print(l[:3])
print(l[::5])
print('chester7cheng'[7:8])


def trim(s):
    start_index = 0
    end_index = 0
    while True:
        if len(s) <= start_index:
            break
        if s[start_index:start_index + 1] == ' ':
            start_index = start_index + 1
            continue
        break
    while True:
        if len(s) < abs(end_index - 1):
            break
        if s[end_index - 1] == ' ':
            end_index = end_index - 1
            continue
        break

    print(start_index)
    print(end_index)
    return s[start_index: (len(s) + end_index)]


source = ' chester7cheng   '
print('-----', trim(source), '--------')
print(len(source), len(trim(source)))

if trim('hello  ') != 'hello':
    print('测试失败!')
elif trim('  hello') != 'hello':
    print('测试失败!')
elif trim('  hello  ') != 'hello':
    print('测试失败!')
elif trim('  hello  world  ') != 'hello  world':
    print('测试失败!')
elif trim('') != '':
    print('测试失败!')
elif trim('    ') != '':
    print('测试失败!')
else:
    print('测试成功!')
